<?php 
/**
 *
 * 管理员查询功能
 */
class AdminSearch
{

	var $pdo = null;
    var $logger = null;
    function __construct()
    {
        $this->pdo = PDOWrapper::instance();
        $this->logger = CLog::getInstance();
    }

    
    //resturant init 1000,user init 10000
    function config($PostArray) {
        $page_no = 0;
        if(isset($PostArray['page_no'])){
            $page_no = $PostArray['page_no'];
        }
        $page_size = 10;
        if(isset($PostArray['page_size'])){
            $page_size = $PostArray['page_size'];
        }
        $sql="SELECT * FROM config ";

        if(isset($PostArray['record_user_id'])){
            $record_user_id = $PostArray['record_user_id'];
            $sql= $sql." WHERE record_user_id={$record_user_id}";
        }

        $sql=  $sql." LIMIT {$start},{$page_size}";
        $config_res = $this->pdo->query($sql);

        $sql="SELECT count(record_id) AS num  FROM config ";
        $count = $this->pdo->query($sql);

        $data = array(
            'num'=>$count[0]['num'],
            'config'=>$config_res
        );

        return $data;
    }

    //
    function order_detail($PostArray) {
        $page_no = 0;
        if(isset($PostArray['page_no'])){
            $page_no = $PostArray['page_no'];
        }
        $page_size = 10;
        if(isset($PostArray['page_size'])){
            $page_size = $PostArray['page_size'];
        }
        $sql="SELECT * FROM order_detail ";

        if(isset($PostArray['record_user_id'])){
            $record_user_id = $PostArray['record_user_id'];
            $sql= $sql." WHERE record_user_id={$record_user_id}";
        }

        $sql=  $sql." LIMIT {$start},{$page_size}";
        $order_detail_res = $this->pdo->query($sql);

        $sql="SELECT count(record_id) AS num  FROM order_detail ";
        $count = $this->pdo->query($sql);

        $data = array(
            'num'=>$count[0]['num'],
            'order_detail'=>$order_detail_res
        );

        return $data;
    }

    //
    function orders($PostArray) {
        $page_no = 0;
        if(isset($PostArray['page_no'])){
            $page_no = $PostArray['page_no'];
        }
        $page_size = 10;
        if(isset($PostArray['page_size'])){
            $page_size = $PostArray['page_size'];
        }
        $sql="SELECT * FROM orders ";

        if(isset($PostArray['record_user_id'])){
            $record_user_id = $PostArray['record_user_id'];
            $sql= $sql." WHERE record_user_id={$record_user_id}";
        }

        $sql=  $sql." LIMIT {$start},{$page_size}";
        $orders_res = $this->pdo->query($sql);

        $sql="SELECT count(record_id) AS num  FROM orders ";
        $count = $this->pdo->query($sql);

        $data = array(
            'num'=>$count[0]['num'],
            'orders'=>$orders_res
        );

        return $data;
    }

    //
    function recipe($PostArray) {
        $page_no = 0;
        if(isset($PostArray['page_no'])){
            $page_no = $PostArray['page_no'];
        }
        $page_size = 10;
        if(isset($PostArray['page_size'])){
            $page_size = $PostArray['page_size'];
        }
        $sql="SELECT * FROM recipe ";

        if(isset($PostArray['record_user_id'])){
            $record_user_id = $PostArray['record_user_id'];
            $sql= $sql." WHERE record_user_id={$record_user_id}";
        }

        $sql=  $sql." LIMIT {$start},{$page_size}";
        $recipe_res = $this->pdo->query($sql);

        $sql="SELECT count(record_id) AS num  FROM recipe ";
        $count = $this->pdo->query($sql);

        $data = array(
            'num'=>$count[0]['num'],
            'recipe'=>$recipe_res
        );

        return $data;
    }

    //
    function recipe_detail($PostArray) {
        $page_no = 0;
        if(isset($PostArray['page_no'])){
            $page_no = $PostArray['page_no'];
        }
        $page_size = 10;
        if(isset($PostArray['page_size'])){
            $page_size = $PostArray['page_size'];
        }
        $sql="SELECT * FROM recipe_detail ";

        if(isset($PostArray['record_user_id'])){
            $record_user_id = $PostArray['record_user_id'];
            $sql= $sql." WHERE record_user_id={$record_user_id}";
        }

        $sql=  $sql." LIMIT {$start},{$page_size}";
        $recipe_detail_res = $this->pdo->query($sql);

        $sql="SELECT count(record_id) AS num  FROM recipe_detail ";
        $count = $this->pdo->query($sql);

        $data = array(
            'num'=>$count[0]['num'],
            'recipe_detail'=>$recipe_detail_res
        );

        return $data;
    }

    //
    function recipe_feature($PostArray) {
        $page_no = 0;
        if(isset($PostArray['page_no'])){
            $page_no = $PostArray['page_no'];
        }
        $page_size = 10;
        if(isset($PostArray['page_size'])){
            $page_size = $PostArray['page_size'];
        }
        $sql="SELECT * FROM recipe_feature ";

        if(isset($PostArray['record_user_id'])){
            $record_user_id = $PostArray['record_user_id'];
            $sql= $sql." WHERE record_user_id={$record_user_id}";
        }

        $sql=  $sql." LIMIT {$start},{$page_size}";
        $recipe_feature_res = $this->pdo->query($sql);

        $sql="SELECT count(record_id) AS num  FROM recipe_feature ";
        $count = $this->pdo->query($sql);

        $data = array(
            'num'=>$count[0]['num'],
            'recipe_feature'=>$recipe_feature_res
        );

        return $data;
    }

    //
    function recipe_type($PostArray) {
        $page_no = 0;
        if(isset($PostArray['page_no'])){
            $page_no = $PostArray['page_no'];
        }
        $page_size = 10;
        if(isset($PostArray['page_size'])){
            $page_size = $PostArray['page_size'];
        }
        $sql="SELECT * FROM recipe_type ";

        if(isset($PostArray['record_user_id'])){
            $record_user_id = $PostArray['record_user_id'];
            $sql= $sql." WHERE record_user_id={$record_user_id}";
        }

        $sql=  $sql." LIMIT {$start},{$page_size}";
        $recipe_type_res = $this->pdo->query($sql);

        $sql="SELECT count(record_id) AS num  FROM recipe_type ";
        $count = $this->pdo->query($sql);

        $data = array(
            'num'=>$count[0]['num'],
            'recipe_type'=>$recipe_type_res
        );

        return $data;
    }

    //
    function restaurant($PostArray) {
        $page_no = 0;
        if(isset($PostArray['page_no'])){
            $page_no = $PostArray['page_no'];
        }
        $page_size = 10;
        if(isset($PostArray['page_size'])){
            $page_size = $PostArray['page_size'];
        }
        $sql="SELECT * FROM restaurant ";

        if(isset($PostArray['record_user_id'])){
            $record_user_id = $PostArray['record_user_id'];
            $sql= $sql." WHERE record_user_id={$record_user_id}";
        }

        $sql=  $sql." LIMIT {$start},{$page_size}";
        $restaurant_res = $this->pdo->query($sql);

        $sql="SELECT count(record_id) AS num  FROM restaurant ";
        $count = $this->pdo->query($sql);

        $data = array(
            'num'=>$count[0]['num'],
            'restaurant'=>$restaurant_res
        );

        return $data;
    }

    //
    function restaurant_label($PostArray) {
        $page_no = 0;
        if(isset($PostArray['page_no'])){
            $page_no = $PostArray['page_no'];
        }
        $page_size = 10;
        if(isset($PostArray['page_size'])){
            $page_size = $PostArray['page_size'];
        }
        $sql="SELECT * FROM restaurant_label ";

        if(isset($PostArray['record_user_id'])){
            $record_user_id = $PostArray['record_user_id'];
            $sql= $sql." WHERE record_user_id={$record_user_id}";
        }

        $sql=  $sql." LIMIT {$start},{$page_size}";
        $restaurant_label_res = $this->pdo->query($sql);

        $sql="SELECT count(record_id) AS num  FROM restaurant_label ";
        $count = $this->pdo->query($sql);

        $data = array(
            'num'=>$count[0]['num'],
            'restaurant_label'=>$restaurant_label_res
        );

        return $data;
    }

    //
    function restaurant_pic($PostArray) {
        $page_no = 0;
        if(isset($PostArray['page_no'])){
            $page_no = $PostArray['page_no'];
        }
        $page_size = 10;
        if(isset($PostArray['page_size'])){
            $page_size = $PostArray['page_size'];
        }
        $sql="SELECT * FROM restaurant_pic ";

        if(isset($PostArray['record_user_id'])){
            $record_user_id = $PostArray['record_user_id'];
            $sql= $sql." WHERE record_user_id={$record_user_id}";
        }

        $sql=  $sql." LIMIT {$start},{$page_size}";
        $restaurant_pic_res = $this->pdo->query($sql);

        $sql="SELECT count(record_id) AS num  FROM restaurant_pic ";
        $count = $this->pdo->query($sql);

        $data = array(
            'num'=>$count[0]['num'],
            'restaurant_pic'=>$restaurant_pic_res
        );

        return $data;
    }

    //
    function users($PostArray) {
        $page_no = 0;
        if(isset($PostArray['page_no'])){
            $page_no = $PostArray['page_no'];
        }
        $page_size = 10;
        if(isset($PostArray['page_size'])){
            $page_size = $PostArray['page_size'];
        }
        $sql="SELECT * FROM users ";

        if(isset($PostArray['record_user_id'])){
            $record_user_id = $PostArray['record_user_id'];
            $sql= $sql." WHERE record_user_id={$record_user_id}";
        }

        $sql=  $sql." LIMIT {$start},{$page_size}";
        $users_res = $this->pdo->query($sql);

        $sql="SELECT count(record_id) AS num  FROM users ";
        $count = $this->pdo->query($sql);

        $data = array(
            'num'=>$count[0]['num'],
            'users'=>$users_res
        );

        return $data;
    }

}